{block #head}
<script type="text/javascript" n:syntax="double">
    var index = 0;
    var updateInfo = [{{foreach $templateEntity->domains as $domain}}[{{$domain->id}}, {{link updateDomain!, $domain->id, $templateEntity->id}}],{{/foreach}}];    
    var numOfSteps = 0;
    
    jQuery.extend({
	cms: {
            updateSnippet: function (id, html) {
                var currHtml = $("#" + id).html();
                $("#" + id).html(currHtml + html);
            },                                
            
            error: function () {
                data = { 
                    updateStatus: false,
                    updateMsg: "{{dictionary updater_updateError}}"
                };
                                
                jQuery.cms.success(data);
            },                                
            
            success: function (payload) {
                hideBar();                                        
                // podarilo se
                if (payload.updateStatus) {
                    var txt = "<span class=\"update-succ\">{{dictionary updater_operationSucc}}</span>";
                    $("#updateStatus" + updateInfo[index][0]).html(txt);
                } else { // na dane domene selhalo
                    var txt = "<span class=\"update-fail\">{{dictionary updater_operationFail}} ("
                        + payload.updateMsg + ") <a href=\"#\" onclick=\"index=" 
                        + index + "; showBar(); $.get('"
                        + updateInfo[index][1] 
                        + "', jQuery.cms.success).error(jQuery.cms.error);\">{{dictionary updater_tryAgain}}</a></span>";
                    $("#updateStatus" + updateInfo[index][0]).html(txt);
                }
                                
                // dalsi krok
                index++;
                if (index < numOfSteps) {
                    showBar();
                    $.get(updateInfo[index][1], jQuery.cms.success)
                        .error(jQuery.cms.error); 
                } else {
                    $.get({{link updateFinish!, $templateEntity->id}}); 
                }
            }
	}
    });
    
    $("#update-button").live("click", function (event) {
        event.preventDefault();         
        numOfSteps = updateInfo.length;
        index = 0;        
        
        showBar();
        $.get(updateInfo[index][1], jQuery.cms.success)
            .error(jQuery.cms.error);
    });
    
    function showBar () {
        var domainId = updateInfo[index][0];
        $("#updateStatus" + domainId).addClass("status-bar");
    }
    
    function hideBar () {
        var domainId = updateInfo[index][0];
        $("#updateStatus" + domainId).removeClass("status-bar");
    }
</script>
{/block}

{block #heading}
    {$title} (<a class="heading-link" href="{plink :Updater:Template:edit, $templateEntity->id}">{$templateEntity->name}</a>)
{/block}
    
{block #content}
    <table>
        <tr>
            <td><strong>{dictionary updater_svnPath} </strong></td>
            <td>{$templateEntity->svnPath}</td>
        </tr>
        <tr>
            <td><strong>{dictionary updater_svnDir} </strong></td>
            <td>{$templateEntity->svnDir}</td>
        </tr>            
        <tr>
            <td><strong>{dictionary updater_modules} </strong></td>
            <td>
                {foreach $templateEntity->modules as $module}
                    {$module}<br />
                {/foreach}
            </td>
        </tr>
        <tr>
            <td><strong>{dictionary updater_domains} </strong></td>
            <td>
                {foreach $templateEntity->domains as $domain}
                    {$domain->name} <div class="updater-status" id="updateStatus{$domain->id}"></div><br />
                {/foreach}
            </td>
        </tr>        
    </table>
    <br />    
    <a n:if="count($templateEntity->domains) > 0" href="{link this}" id="update-button" class="a-button">{dictionary update_doUpdate}</a>
    
    {if $lastUpdate !== NULL}
    <h2>{dictionary updater_lastUpdate}</h2>
    <table>
        <tr>
            <td><strong>{dictionary updater_date} </strong></td>
            <td>{?echo $lastUpdate->date->format("j.n.Y G:i")}</td>
        </tr>
        <tr>
            <td><strong>{dictionary updater_svnPath} </strong></td>
            <td>{$lastUpdate->svnPath}</td>
        </tr>
        <tr>
            <td><strong>{dictionary updater_svnDir} </strong></td>
            <td>{$lastUpdate->svnDir}</td>
        </tr>            
        <tr>
            <td><strong>{dictionary updater_modules} </strong></td>
            <td>
                {foreach $lastUpdate->modules as $module}
                    {$module}<br />
                {/foreach}
            </td>
        </tr>
        <tr>
            <td><strong>{dictionary updater_domains} </strong></td>
            <td>
                {foreach $lastUpdate->domains as $domain}
                    {$domain->name}<br />
                {/foreach}
            </td>
        </tr>        
    </table>    
    {/if}
{/block}